package com.example.administrator.befoolishdragsortrecyclerview;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * Created by Administrator on 2019/1/24.
 */

public class MyRecyclerView extends RecyclerView {

    private boolean onDraging;

    public MyRecyclerView(Context context) {
        super(context);
    }

    public MyRecyclerView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (onDraging && ev.getAction() == MotionEvent.ACTION_MOVE) {//这里是根据业务来处理滑动冲突，
            getParent().requestDisallowInterceptTouchEvent(true);     //当RecyclerView处于可以拖拽状态时，MOVE事件由RecyclerView
        } else {                                                    //消费，否则由外部ScrollView消费
            getParent().requestDisallowInterceptTouchEvent(false);
        }
        return super.dispatchTouchEvent(ev);
    }

    public void setOnDraging(boolean onDraging) {
        this.onDraging = onDraging;
    }
}
